package cst.a931xmc.yuejian20.Model;

import cst.a931xmc.yuejian20.Bean.RegisterBean;
import cst.a931xmc.yuejian20.Interface.RegisterIface;
import cst.a931xmc.yuejian20.Listener.Listener;
import cst.a931xmc.yuejian20.Service.RegisterService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RegisterModel<T> extends ApiModel implements RegisterIface {
    private Retrofit retrofit;
    private RegisterService service;

    public RegisterModel(){
        retrofit = new Retrofit
                .Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service = retrofit.create(RegisterService.class);
    }

    @Override
    public void register(String user_tel, String user_password, final Listener l) {
        Call<RegisterBean> call = service.register(user_tel,user_password);
        call.enqueue(new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                l.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                l.onFail(t.toString());
            }
        });
    }
}
